var express = require('express')
var app = express()
app.use(express.static('state'))

var arr = [
    { id: '810000198906163357', email: 'w.tvrmn@qhvksk.aq', name: '龚明', phone: 18011796113, zu: '编辑组', zhuang: false, pass: 1234 },
    { id: '540000198611284105', email: 'p.vlwqr@heno.pl', name: '汤芳', phone: 14114407069, zu: '开发组', zhuang: true, pass: 1234 },
    { id: '640000197109121158', email: 'c.zdatvit@dmpleas.com.cn', name: '崔秀兰', phone: 19913090954, zu: '技术组', zhuang: false, pass: 1234 },
    { id: '620000199605278555', email: 'q.jcg@ilvozcn.tv', name: '吴秀英', phone: 14565782686, zu: '管理组', zhuang: true, pass: 1234 },
    { id: '360000198804117617', email: 'r.bdoses@kzmu.ee', name: '毛芳', phone: 14775167915, zu: '销售组', zhuang: false, pass: 1234 },
    { id: '460000200701268053', email: 'p.nquev@fqbcg.de', name: '胡丽', phone: 15326688815, zu: '编辑组', zhuang: true, pass: 1234 },
    { id: '130000197308202479', email: 'd.dexzmagyt@bllyntkklb.sc', name: '谢磊', phone: 14110807553, zu: '开发组', zhuang: true, pass: 1234 },
    { id: '820000202209022744', email: 'x.rqbnxxk@dvcow.ni', name: '吕秀兰', phone: 16563288494, zu: '技术组', zhuang: false, pass: 1234 },
    { id: '620000197107068986', email: 's.uqxkp@vom.si', name: '卢娜', phone: 13192737628, zu: '管理组', zhuang: false, pass: 1234 },
    { id: '62000019940225115X', email: 'e.ifhm@ibsowbj.sb', name: '邹芳', phone: 16333762334, zu: '销售组', zhuang: true, pass: 1234 }
]
app.use(express.json())
app.use(express.urlencoded({ extended: false }))
// 请求数据渲染页面，分页
app.get('/user/last', (req, res) => {
    var { page, count } = req.query
    console.log(page, count);
    var ye = Math.ceil(arr.length / count)
    var arr1 = arr.slice((page - 1) * count, page * count)
    res.send({ code: 200, msg: '请求成功！', list: arr1, li: ye })
})
// 内容搜索
app.get('/user/two', (req, res) => {
    var { searchkey } = req.query
    var arr2 = arr.filter((item) => {
        return item.name.includes(searchkey)
    })
    res.send({ code: 200, msg: '查询成功!', list: arr2 })
})
// 登录请求
app.post('/user/deng', (req, res) => {
    var { phone, pass } = req.body
    var a = arr.findIndex((item) => {
        return item.phone == phone && item.pass == pass
    })
    if (a == -1) {
        res.send({ code: 400, msg: '登陆失败!' });
    } else {
        res.send({ code: 200, msg: '登陆成功!', userinfo: arr[a], token: '' });
    }
})
app.listen(8888, () => {
    console.log('服务器端');
})